home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 051-075 / 074 / less / output.c < prev    next >
C/C++ Source or Header  |  1995-03-13  |  3KB  |  206 lines

  1. /*
  2.  * High level routines dealing with the output to the screen.
  3.  */
  4.  
  5. #include "less.h"
  6.  
  7. extern int sigs;
  8. extern int sc_width, sc_height;
  9. extern int ul_width, ue_width;
  10. extern int so_width, se_width;
  11. extern int tabstop;
  12. extern int twiddle;
  13. extern char *line;
  14. extern char *first_cmd;
  15.  
  16.  
  17. /*
  18.  * Display the line which is in the line buffer.
  19.  */
  20.     public void
  21. put_line()
  22. {
  23.     register char *p;
  24.     register int c;
  25.     register int column;
  26.     extern int auto_wrap, ignaw;
  27.  
  28.     if (sigs)
  29.         /*
  30.          * Don't output if a signal is pending.
  31.          */
  32.         return;
  33.  
  34.     if (line == NULL)
  35.         line = (twiddle) ? "~" : "";
  36.  
  37.     column = 0;
  38.     for (p = line;  *p != '\0';  p++)
  39.     {
  40.         switch (c = *p)
  41.         {
  42.         case UL_CHAR:
  43.             ul_enter();
  44.             column += ul_width;
  45.             break;
  46.         case UE_CHAR:
  47.             ul_exit();
  48.             column += ue_width;
  49.             break;
  50.         case '\t':
  51.             do
  52.             {
  53.                 putc(' ');
  54.                 column++;
  55.             } while ((column % tabstop) != 0);
  56.             break;
  57.         case '\b':
  58.             putbs();
  59.             column--;
  60.             break;
  61.         default:
  62.             if (c & 0200)
  63.             {
  64.                 putc('^');
  65.                 putc(c & 0177);
  66.                 column += 2;
  67.             } else
  68.             {
  69.                 putc(c);
  70.                 column++;
  71.             }
  72.         }
  73.     }
  74.     if (column < sc_width || !auto_wrap || ignaw)
  75.         putc('\n');
  76. }
  77.  
  78. /*
  79.  * Is a given character a "control" character?
  80.  * {{ ASCII DEPENDENT }}
  81.  */
  82.     public int
  83. control_char(c)
  84.     int c;
  85. {
  86.     return (c < ' ' || c == '\177');
  87. }
  88.  
  89. /*
  90.  * Return the printable character used to identify a control character
  91.  * (printed after a carat; e.g. '\3' => "^C").
  92.  * {{ ASCII DEPENDENT }}
  93.  */
  94.     public int
  95. carat_char(c)
  96.     int c;
  97. {
  98.     return ((c == '\177') ? '?' : (c | 0100));
  99. }
  100.  
  101. static char obuf[1024];
  102. static char *ob = obuf;
  103.  
  104. /*
  105.  * Flush buffered output.
  106.  */
  107. public void
  108. flush()
  109. {
  110. #ifdef amiga
  111.     extern struct FileHandle *tty;
  112.     extern nrow;
  113.  
  114.     if (nrow == 0)
  115.         ttopen();
  116.  
  117.     ttflush();
  118.     Write(tty, obuf, (long) ob-obuf);
  119. #else
  120.     write(1, obuf, ob-obuf);
  121. #endif
  122.     ob = obuf;
  123. }
  124.  
  125. /*
  126.  * Discard buffered output.
  127.  */
  128.     public void
  129. dropout()
  130. {
  131.     ob = obuf;
  132. }
  133.  
  134. /*
  135.  * Output a character.
  136.  */
  137.     public void
  138. putc(c)
  139. int c;
  140. {
  141.     if (ob >= &obuf[sizeof(obuf)])
  142.         flush();
  143.  
  144.     *ob++ = c;
  145. }
  146.  
  147. /*
  148.  * Output a string.
  149.  */
  150.     public void
  151. puts(s)
  152.     register char *s;
  153. {
  154.     while (*s != '\0')
  155.         putc(*s++);
  156. }
  157.  
  158.  
  159. /*
  160.  * Output a message in the lower left corner of the screen
  161.  * and wait for carriage return.
  162.  */
  163.  
  164. static char return_to_continue[] = "  (press RETURN)";
  165.  
  166. public void
  167. error(s)
  168.     char *s;
  169. {
  170.     register int c;
  171.     static char buf[2];
  172.  
  173.     lower_left();
  174.     clear_eol();
  175.     so_enter();
  176.     puts(s);
  177.     puts(return_to_continue);
  178.     so_exit();
  179.  
  180. #if ONLY_RETURN
  181.     while ((c = getc()) != '\n' && c != '\r')
  182.         bell();
  183. #else
  184.     c = getc();
  185.     if (c != '\n' && c != '\r' && c != ' ')
  186.     {
  187.         buf[0] = c;
  188.         first_cmd = buf;
  189.     }
  190. #endif
  191.  
  192.     if (strlen(s) > sc_width)
  193.         repaint();
  194. }
  195.  
  196.     public int
  197. error_width()
  198. {
  199.     /*
  200.      * Don't use the last position, because some terminals
  201.      * will scroll if you write in the last char of the last line.
  202.      */
  203.     return (sc_width - 
  204.         (sizeof(return_to_continue) + so_width + se_width + 1));
  205. }
  206.